import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
import home from '@/views/Home.vue'
import rolemanage from '@/views/usermanage/rolemanage.vue';
import menuMange from '@/views/usermanage/menumanage.vue'
import Login from '@/views/login.vue';
import departManage from '@/views/usermanage/departManage.vue'
import jobManage from '@/views/usermanage/jobManage.vue'
import rentManage from '@/views/usermanage/rentManage.vue'
import dashboard from '@/views/dashboard/dashbord.vue'
const routes = [
    {path : '/login', name : 'login', component : Login,},
    {path: '/admin/user/index', name: 'Home', component: home ,meta :{title : '用户管理'}},
    {path :'/admin/role/index',name : 'Role',component : rolemanage,meta :{title : '角色管理'}},
    {path :'/admin/menu/index',name : 'MenuManage',component : menuMange,meta :{title : '菜单管理'}},
    {path :'/admin/dept/index',name : 'DepartManage',component : departManage,meta :{title : '部门管理'}},
    {path :'/admin/post/index',name : 'JobManage',component : jobManage,meta :{title : '岗位管理'}},
    {path :'/rentManage',name : 'RentManage',component : rentManage,meta :{title : '租户管理'}},
    {path :'/dashboard',name : 'Dashboard',component : dashboard,meta :{title : '工作台'}}
];

const router = createRouter({
    // history: createWebHistory('/'),
    history: createWebHashHistory(),
    routes,
});
router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token')
    if (to.path === '/login' || token) {
    next();
    } else {
    next('/login');
}
});
export default router;